package com.yunzhou.action;

import com.yunzhou.utils.LogTool;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import weaver.interfaces.datasource.DataSource;
import weaver.general.StaticObj;

public class FlyriseInsertmaterialappvouchAction implements Action {

	private static Log log = LogFactory.getLog(FlyriseInsertmaterialappvouchAction.class.getName());
	private LogTool logTool = new LogTool("/log/huangwm/u8/action/FlyriseInsertmaterialappvouchAction",false);

	@Override
	public String execute(RequestInfo requestInfo) {

		String requestID = requestInfo.getRequestid();
		String workflowid = requestInfo.getWorkflowid();
		log.info((new StringBuilder()).append("FlyriseInsertmaterialappvouchAction开始====").append(requestID)
				.append("，workflowid：").append(workflowid).toString());
		logTool.writeLog("FlyriseInsertmaterialappvouchAction requestid="+requestID);
		DataSource ds = (DataSource) StaticObj.getServiceByFullname(
				("datasource.ERP601"), DataSource.class);
		Connection conn = null;
		String msg = "";
		try {
			conn = ds.getConnection();
			ResultSet rs = conn.createStatement().executeQuery
					("exec sp_flyrise_insertmaterialappvouch " + requestID);
			while (rs.next()) {
				log.info("FlyriseInsertmaterialappvouchAction2222222222===="+rs.getString("msg"));
				logTool.writeLog("FlyriseInsertmaterialappvouchAction msg="+msg);
				if (rs.getInt("flag") == 0) {
					msg = rs.getString("msg");
				} 
			}
			rs.close();
		} catch (Exception e) { 
			msg = e.getMessage();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {
				msg = e.getMessage();
			}
		}

		if (!msg.equals("")) {
			log.info("FlyriseInsertmaterialappvouchAction错误===="+msg);
			requestInfo.getRequestManager().setMessageid("9999999");
			requestInfo.getRequestManager().setMessagecontent(msg);
			return Action.FAILURE_AND_CONTINUE;
		}
		else {
			return Action.SUCCESS;
		}

	}

}
